<?php
    if(isset($_POST["id"])) {$identifiant = $_POST["id"];} else{$identifiant = "";}
    if(isset($_POST["ligne"])) {$ligne = $_POST["ligne"];} else{$ligne = "";}
    
    require_once '../include/class.pdoSio.inc.php';
    
    if($identifiant <> "") {
        $pdo = PdoSio::getPdoSio();
        $req = $pdo->requeteSelection("SELECT id_utilisateur FROM utilisateurs WHERE identifiant = '".$identifiant."'");
        $id_etudiant = $req[0]['id_utilisateur'];
    } else {$id_etudiant = 0;}

    if($identifiant <> "" && $id_etudiant == $ligne) {
            $pdo = PdoSio::getPdoSio();
            $etudiants = $pdo->requeteSelection("SELECT * FROM cv_photo WHERE id_utilisateur =".$ligne);
            if($etudiants[0] == "") {
                echo "<div class='row'><div class='span3 offset4'><div><a href='index.php?uc=cv&action=ajouter&table=photo&ligne=".$ligne."' class='btn btn-xs btn-primary' name='ajouter'><span class='glyphicon glyphicon-plus'></span><img src='./styles/img/plus.png'/></a><br>";
                echo "<div class='photo'></div></div></div>";
            } else {
                foreach ($etudiants as $unEtudiant) {
                    file_put_contents("../styles/img/".$ligne.".png",$unEtudiant['photo']);
                    echo "<div class='row'><div class='span3 offset4'><div class='photo'><img src='./styles/img/".$ligne.".png' /><br><br>";
                    echo "<a href='index.php?uc=cv&action=modifier&table=photo&ligne=".$unEtudiant['id_cv_photo']."' class='btn btn-xs btn-primary' name='modifier'><span class='glyphicon glyphicon-pencil'></span><img src='./styles/img/stylo.png'></i></a>&nbsp;
                        <a href='index.php?uc=cv&action=supprimer&table=photo&ligne=".$unEtudiant['id_cv_photo']."' class='btn btn-xs btn-primary' name='supprimer'><span class='glyphicon glyphicon-trash'></span><img src='./styles/img/moins.png'></i></a></div></div></div>";
                }
            }
            echo "</div>";
    } else {
        $pdo = PdoSio::getPdoSio();
        $etudiants = $pdo->requeteSelection("SELECT * FROM cv_photo WHERE id_utilisateur =".$ligne);
        foreach ($etudiants as $unEtudiant) {
            if($unEtudiant['photo'] == NULL) {
                echo "<div class='row'><div class='span3 offset4'><div class='photo'></div></div></div>";
            } else {
                file_put_contents("../styles/img/".$ligne.".png",$unEtudiant['photo']);
                echo "<div class='row'><div class='span3 offset4'><div class='photo'><img src='./styles/img/".$ligne.".png' /></div></div></div><br>";
            }
        }
    }
  

